/*
main.cpp
19/05/2014
psycommando@gmail.com

Description:

No Crappyrights. All wrongs reversed !
*/
#include <iostream>
#include <cassert>
#include <exception>
#include "basetypes.hpp"

#if   defined(RUN_UNPX)
    #include "ppx_extractor.hpp"
#elif defined(RUN_PXCOMP)
    #include "ppx_compressor.hpp"
#elif defined(RUN_SPRITE_EX)
    #include "pspr_extractor.hpp"
#elif defined(RUN_PACK_TOOLS)
    #include "ppack_tools.hpp"
#elif defined(RUN_SPRITE_ANALYSER)
    #include "pspr_analyser.hpp"
#elif defined(RUN_KAO_UTIL)
    #include "pkao_util.hpp"
#endif

using namespace std;


//====================================================================
// Stuff
//====================================================================

int ScratchpadMain( int argc, const char * argv[] )
{
    assert(false);
    return 0;
}

//====================================================================
// Main
//====================================================================
int main( int argc, const char * argv[] )
{
    int returnval = 0;

    try
    {
#ifdef RUN_UNPX
        returnval = ppx_extract::RunPPXExtract( argc, argv );
#elif defined(RUN_PXCOMP)
        returnval = ppx_compress::RunPPXCompress(argc, argv );
#elif defined(RUN_SPRITE_EX)
        returnval = pspr_extract::RunPSPRExtract( argc, argv );
#elif defined(RUN_PACK_TOOLS)
        returnval = ppack_tools::RunPPackTools( argc, argv );
#elif defined(RUN_SPRITE_ANALYSER)
        returnval = pspr_analyser::RunPSPRAnalyser( argc, argv );
#elif defined(RUN_KAO_UTIL)
        returnval = pkao_util::RunPKaoUtil( argc, argv );
#else
        returnval = ScratchpadMain( argc, argv );
#endif
    }
    catch( std::system_error syser )
    {
        cerr << "-------------\n"
             << "System Error!\n"
             << "-------------\n"
             << "The operating system interupted the program with this error :\n"
             << "ErrorCode " <<syser.code().value() <<" : \"" << syser.what() << "\"\n"
             << "Aborting and returning system error code!\n"
             << "-------------\n"
             << endl;
        returnval = syser.code().value();
        assert(false);
    }
    catch( std::exception e )
    {
        cerr << "-------------\n"
             << "EXCEPTION!\n"
             << "-------------\n"
             << "The program encountered this problem:\n"
             << "   \"" << e.what() << "\"\n"
             << "The program must now stop.. Aborting..\n"
             << "Please notify the coder if you get this message. Its really not supposed to happen..\n"
             << "-------------\n"
             << endl;
        returnval = -1;
        assert(false);
    }

    return returnval;
}

